package com.bwbear.db.splitdb.utils;

import com.bwbear.db.splitdb.config.DataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import online.bwbear.core.utils.functional.OneStringFunctional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 张照威
 * @date 2020/10/16
 * @mail 865533614@qq.com
 * @describe
 */
@Slf4j
public class DataSourceHandlerUtils {

    public static void handleDataSource(List<String> tenantCodeList, OneStringFunctional functional){
        tenantCodeList.stream().forEach(tenantCode->{
            DataSourceContextHolder.setDataSource(tenantCode);
            log.info("开始对{}进行操作",tenantCode);
            functional.doTask(tenantCode);
            DataSourceContextHolder.clear();
            log.info("结束对{}进行操作",tenantCode);
        });
    }

}
